/**
 * @author Burcak Otlu Saritas
 *
 * 
 */

package annotate.intervals.parametric;

import intervaltree.Interval;
import intervaltree.IntervalTree;
import intervaltree.IntervalTreeNode;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import keggpathway.ncbigenes.KeggPathway;

import annotate.encode.Commons;

public class AnnotateIntervalsForGivenParameters {

	public void createChromBaseSeachInputFiles(List<BufferedWriter> bufferedWriterList){
		try {
			FileWriter fileWriter1 	= new FileWriter(Commons.SEARCH_CHR1_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter2 	= new FileWriter(Commons.SEARCH_CHR2_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter3 	= new FileWriter(Commons.SEARCH_CHR3_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter4 	= new FileWriter(Commons.SEARCH_CHR4_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter5 	= new FileWriter(Commons.SEARCH_CHR5_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter6 	= new FileWriter(Commons.SEARCH_CHR6_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter7	= new FileWriter(Commons.SEARCH_CHR7_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter8 	= new FileWriter(Commons.SEARCH_CHR8_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter9 	= new FileWriter(Commons.SEARCH_CHR9_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter10 = new FileWriter(Commons.SEARCH_CHR10_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter11 = new FileWriter(Commons.SEARCH_CHR11_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter12 = new FileWriter(Commons.SEARCH_CHR12_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter13 = new FileWriter(Commons.SEARCH_CHR13_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter14 = new FileWriter(Commons.SEARCH_CHR14_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter15 = new FileWriter(Commons.SEARCH_CHR15_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter16 = new FileWriter(Commons.SEARCH_CHR16_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter17 = new FileWriter(Commons.SEARCH_CHR17_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter18 = new FileWriter(Commons.SEARCH_CHR18_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter19 = new FileWriter(Commons.SEARCH_CHR19_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter20 = new FileWriter(Commons.SEARCH_CHR20_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter21 = new FileWriter(Commons.SEARCH_CHR21_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter22 = new FileWriter(Commons.SEARCH_CHR22_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter23 = new FileWriter(Commons.SEARCH_CHRX_USING_INTERVAL_TREE_INPUT_FILE);
			FileWriter fileWriter24 = new FileWriter(Commons.SEARCH_CHRY_USING_INTERVAL_TREE_INPUT_FILE);
			
			BufferedWriter bufferedWriter1 	= new BufferedWriter(fileWriter1);
			BufferedWriter bufferedWriter2 	= new BufferedWriter(fileWriter2);
			BufferedWriter bufferedWriter3 	= new BufferedWriter(fileWriter3);
			BufferedWriter bufferedWriter4 	= new BufferedWriter(fileWriter4);
			BufferedWriter bufferedWriter5 	= new BufferedWriter(fileWriter5);
			BufferedWriter bufferedWriter6 	= new BufferedWriter(fileWriter6);
			BufferedWriter bufferedWriter7 	= new BufferedWriter(fileWriter7);
			BufferedWriter bufferedWriter8 	= new BufferedWriter(fileWriter8);
			BufferedWriter bufferedWriter9 	= new BufferedWriter(fileWriter9);
			BufferedWriter bufferedWriter10 = new BufferedWriter(fileWriter10);
			BufferedWriter bufferedWriter11 = new BufferedWriter(fileWriter11);
			BufferedWriter bufferedWriter12 = new BufferedWriter(fileWriter12);
			BufferedWriter bufferedWriter13 = new BufferedWriter(fileWriter13);
			BufferedWriter bufferedWriter14 = new BufferedWriter(fileWriter14);
			BufferedWriter bufferedWriter15 = new BufferedWriter(fileWriter15);
			BufferedWriter bufferedWriter16 = new BufferedWriter(fileWriter16);
			BufferedWriter bufferedWriter17 = new BufferedWriter(fileWriter17);
			BufferedWriter bufferedWriter18 = new BufferedWriter(fileWriter18);
			BufferedWriter bufferedWriter19 = new BufferedWriter(fileWriter19);
			BufferedWriter bufferedWriter20 = new BufferedWriter(fileWriter20);
			BufferedWriter bufferedWriter21 = new BufferedWriter(fileWriter21);
			BufferedWriter bufferedWriter22 = new BufferedWriter(fileWriter22);
			BufferedWriter bufferedWriter23 = new BufferedWriter(fileWriter23);
			BufferedWriter bufferedWriter24 = new BufferedWriter(fileWriter24);
			
			bufferedWriterList.add(bufferedWriter1);
			bufferedWriterList.add(bufferedWriter2);
			bufferedWriterList.add(bufferedWriter3);
			bufferedWriterList.add(bufferedWriter4);
			bufferedWriterList.add(bufferedWriter5);
			bufferedWriterList.add(bufferedWriter6);
			bufferedWriterList.add(bufferedWriter7);
			bufferedWriterList.add(bufferedWriter8);
			bufferedWriterList.add(bufferedWriter9);
			bufferedWriterList.add(bufferedWriter10);
			bufferedWriterList.add(bufferedWriter11);
			bufferedWriterList.add(bufferedWriter12);
			bufferedWriterList.add(bufferedWriter13);
			bufferedWriterList.add(bufferedWriter14);
			bufferedWriterList.add(bufferedWriter15);
			bufferedWriterList.add(bufferedWriter16);
			bufferedWriterList.add(bufferedWriter17);
			bufferedWriterList.add(bufferedWriter18);
			bufferedWriterList.add(bufferedWriter19);
			bufferedWriterList.add(bufferedWriter20);
			bufferedWriterList.add(bufferedWriter21);
			bufferedWriterList.add(bufferedWriter22);
			bufferedWriterList.add(bufferedWriter23);
			bufferedWriterList.add(bufferedWriter24);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public void writeChromBaseSearchInputFile(String chromName, String strLine, List<BufferedWriter> bufList){
		try {
			
			if (chromName.equals(Commons.CHROMOSOME1)){
				bufList.get(0).write(strLine + "\n");
				bufList.get(0).flush();		
			} else 	if (chromName.equals(Commons.CHROMOSOME2)){
				bufList.get(1).write(strLine + "\n");
				bufList.get(1).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME3)){
				bufList.get(2).write(strLine + "\n");
				bufList.get(2).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME4)){
				bufList.get(3).write(strLine + "\n");
				bufList.get(3).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME5)){
				bufList.get(4).write(strLine + "\n");
				bufList.get(4).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME6)){
				bufList.get(5).write(strLine + "\n");
				bufList.get(5).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME7)){
				bufList.get(6).write(strLine + "\n");
				bufList.get(6).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME8)){
				bufList.get(7).write(strLine + "\n");
				bufList.get(7).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME9)){
				bufList.get(8).write(strLine + "\n");
				bufList.get(8).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME10)){
				bufList.get(9).write(strLine + "\n");
				bufList.get(9).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME11)){
				bufList.get(10).write(strLine + "\n");
				bufList.get(10).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME12)){
				bufList.get(11).write(strLine + "\n");
				bufList.get(11).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME13)){
				bufList.get(12).write(strLine + "\n");
				bufList.get(12).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME14)){
				bufList.get(13).write(strLine + "\n");
				bufList.get(13).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME15)){
				bufList.get(14).write(strLine + "\n");
				bufList.get(14).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME16)){
				bufList.get(15).write(strLine + "\n");
				bufList.get(15).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME17)){
				bufList.get(16).write(strLine + "\n");
				bufList.get(16).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME18)){
				bufList.get(17).write(strLine + "\n");
				bufList.get(17).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME19)){
				bufList.get(18).write(strLine + "\n");
				bufList.get(18).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME20)){
				bufList.get(19).write(strLine + "\n");
				bufList.get(19).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME21)){
				bufList.get(20).write(strLine + "\n");
				bufList.get(20).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOME22)){
				bufList.get(21).write(strLine + "\n");
				bufList.get(21).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOMEX)){
				bufList.get(22).write(strLine + "\n");
				bufList.get(22).flush();		
			}else 	if (chromName.equals(Commons.CHROMOSOMEY)){
				bufList.get(23).write(strLine + "\n");
				bufList.get(23).flush();		
			}else{
				System.out.println("Unknown chromosome");
			}

		
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void partitionSearchInputFilePerChromName(String inputFileName, List<BufferedWriter> bufferedWriterList){
		
		FileReader fileReader = null;
		BufferedReader bufferedReader = null;
		
		String strLine;
		int indexofFirstTab;
		String chromName;
		
		try {
			fileReader = new FileReader(inputFileName);
			bufferedReader = new BufferedReader(fileReader);
			
			while((strLine=bufferedReader.readLine())!=null){
				
				indexofFirstTab = strLine.indexOf('\t');
				chromName = strLine.substring(0,indexofFirstTab);
				writeChromBaseSearchInputFile(chromName,strLine,bufferedWriterList);
				
			} // End of While
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			bufferedReader.close();
			fileReader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}				
	}
	
	public void closeBufferedWriterList(List<BufferedWriter> bufferedWriterList){
		for(int i = 0; i<bufferedWriterList.size(); i++){
			try {
				bufferedWriterList.get(i).close();
			} catch (IOException e) {
				e.printStackTrace();
			}			
		}
	}
	
	public IntervalTree generateEncodeDnaseIntervalTree(BufferedReader bufferedReader, List<String> dnaseList) {
		IntervalTree dnaseIntervalTree = new IntervalTree();
		String strLine;
		
		int indexofFirstTab = 0;
		int indexofSecondTab = 0;
		int indexofThirdTab = 0;
		int indexofFourthTab = 0;
		
		int startPosition = 0;
		int endPosition = 0;
		
		String chromName;
		String cellLineName;
		String fileName;
		
		
		try {
			while((strLine = bufferedReader.readLine())!=null){
//				example strLine
//				chr1	91852781	91853156	GM12878	idrPool.GM12878-DS9432-DS10671.z_OV_GM12878-DS10671.z_VS_GM12878-DS9432.z.npk2.narrowPeak

				indexofFirstTab = strLine.indexOf('\t');
				indexofSecondTab = strLine.indexOf('\t', indexofFirstTab+1);
				indexofThirdTab = strLine.indexOf('\t', indexofSecondTab+1);
				indexofFourthTab = strLine.indexOf('\t', indexofThirdTab+1);
					
				chromName = strLine.substring(0,indexofFirstTab);
				startPosition = Integer.parseInt(strLine.substring(indexofFirstTab+1,indexofSecondTab));
				endPosition = Integer.parseInt(strLine.substring(indexofSecondTab+1, indexofThirdTab));
				cellLineName = strLine.substring(indexofThirdTab+1, indexofFourthTab);
				fileName = strLine.substring(indexofFourthTab+1);
				
//				todo if dnase exists in dnaseList 
				if (dnaseList.contains(cellLineName)){
//					Creating millions of nodes with six attributes causes out of memory error
					IntervalTreeNode node = new IntervalTreeNode(chromName,startPosition,endPosition,cellLineName,fileName);
					dnaseIntervalTree.intervalTreeInsert(dnaseIntervalTree, node);
					
				}

								
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return dnaseIntervalTree;
	}
	
	public IntervalTree generateEncodeTfbsIntervalTree(BufferedReader bufferedReader, List<String> tfbsList){
		IntervalTree tfbsIntervalTree = new IntervalTree();
		String strLine;
		
		int indexofFirstTab = 0;
		int indexofSecondTab = 0;
		int indexofThirdTab = 0;
		int indexofFourthTab = 0;
		int indexofFifthTab = 0;
		
		int startPosition = 0;
		int endPosition = 0;
		
		String chromName;
		String tfbsName;
		String cellLineName;
		String fileName;
		
	
		try {
			while((strLine = bufferedReader.readLine())!=null){
//				exampple strLine
//				chrY	2804079	2804213	Ctcf	H1hesc	spp.optimal.wgEncodeBroadHistoneH1hescCtcfStdAlnRep0_VS_wgEncodeBroadHistoneH1hescControlStdAlnRep0.narrowPeak
			
				indexofFirstTab = strLine.indexOf('\t');
				indexofSecondTab = strLine.indexOf('\t', indexofFirstTab+1);
				indexofThirdTab = strLine.indexOf('\t', indexofSecondTab+1);
				indexofFourthTab = strLine.indexOf('\t', indexofThirdTab+1);
				indexofFifthTab = strLine.indexOf('\t', indexofFourthTab+1);
					
				chromName = strLine.substring(0,indexofFirstTab);
				startPosition = Integer.parseInt(strLine.substring(indexofFirstTab+1,indexofSecondTab));
				endPosition = Integer.parseInt(strLine.substring(indexofSecondTab+1, indexofThirdTab));
				tfbsName = strLine.substring(indexofThirdTab+1, indexofFourthTab);
				cellLineName = strLine.substring(indexofFourthTab+1, indexofFifthTab);
				fileName = strLine.substring(indexofFifthTab+1);

//				todo if tfbs exists in tfbsList 

				if (tfbsList.contains(tfbsName)){
//					Creating millions of nodes with six attributes causes out of memory error
					IntervalTreeNode node = new IntervalTreeNode(chromName,startPosition,endPosition,tfbsName,cellLineName,fileName);
					tfbsIntervalTree.intervalTreeInsert(tfbsIntervalTree, node);					
				}
								
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return tfbsIntervalTree;
	}

	public IntervalTree generateEncodeHistoneIntervalTree(BufferedReader bufferedReader, List<String> histoneList) {
		IntervalTree histoneIntervalTree = new IntervalTree();
		String strLine;
		
		int indexofFirstTab = 0;
		int indexofSecondTab = 0;
		int indexofThirdTab = 0;
		int indexofFourthTab = 0;
		int indexofFifthTab = 0;
				
		String chromName;
		int startPosition = 0;
		int endPosition = 0;
		
		String histoneName;
		String cellLineName;
		String fileName;
		
		
		try {
			while((strLine = bufferedReader.readLine())!=null){
//				example strLine
//				chr9	131533188	131535395	H2az	Gm12878	wgEncodeBroadHistoneGm12878H2azStdAln.narrowPeak

				indexofFirstTab = strLine.indexOf('\t');
				indexofSecondTab = strLine.indexOf('\t', indexofFirstTab+1);
				indexofThirdTab = strLine.indexOf('\t', indexofSecondTab+1);
				indexofFourthTab = strLine.indexOf('\t', indexofThirdTab+1);
				indexofFifthTab = strLine.indexOf('\t', indexofFourthTab+1);
					
				chromName = strLine.substring(0,indexofFirstTab);
				startPosition = Integer.parseInt(strLine.substring(indexofFirstTab+1,indexofSecondTab));
				endPosition = Integer.parseInt(strLine.substring(indexofSecondTab+1, indexofThirdTab));				
				histoneName = strLine.substring(indexofThirdTab+1, indexofFourthTab);
				cellLineName = strLine.substring(indexofFourthTab+1,indexofFifthTab);
				fileName = strLine.substring(indexofFifthTab+1);

// todo histoneList
				if (histoneList.contains(histoneName)){
//					Creating millions of nodes with six attributes causes out of memory error
					IntervalTreeNode node = new IntervalTreeNode(chromName,startPosition,endPosition,histoneName,cellLineName,fileName);
					histoneIntervalTree.intervalTreeInsert(histoneIntervalTree, node);
					
				}
								
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return histoneIntervalTree;
	}

	public IntervalTree generateUcscRefSeqGenesIntervalTree(BufferedReader bufferedReader, List<String> ucscRefSeqGeneList){
		IntervalTree tree = new IntervalTree();
		String strLine;
		
		int indexofFirstTab = 0;
		int indexofSecondTab = 0;
		int indexofThirdTab = 0;
		int indexofFourthTab = 0;
		int indexofFifthTab = 0;
		int indexofSixthTab = 0;
		int indexofSeventhTab = 0;
		
		int startPosition = 0;
		int endPosition = 0;
		
		String chromName;
		String  refSeqGeneName;
		Integer geneEntrezId;
		String intervalName;
		String geneHugoSymbol;
		
		try {
			while((strLine = bufferedReader.readLine())!=null){
//				example strLine
//				chr17	67074846	67075215	NM_080284	23460	Exon1	-	ABCA6

				indexofFirstTab = strLine.indexOf('\t');
				indexofSecondTab = strLine.indexOf('\t', indexofFirstTab+1);
				indexofThirdTab = strLine.indexOf('\t', indexofSecondTab+1);
				indexofFourthTab = strLine.indexOf('\t', indexofThirdTab+1);
				indexofFifthTab = strLine.indexOf('\t', indexofFourthTab+1);
				indexofSixthTab = strLine.indexOf('\t', indexofFifthTab+1);
				indexofSeventhTab = strLine.indexOf('\t',indexofSixthTab+1);	
				
				chromName = strLine.substring(0,indexofFirstTab);
				startPosition = Integer.parseInt(strLine.substring(indexofFirstTab+1,indexofSecondTab));
				endPosition = Integer.parseInt(strLine.substring(indexofSecondTab+1, indexofThirdTab));
				refSeqGeneName = strLine.substring(indexofThirdTab+1, indexofFourthTab);
				geneEntrezId = Integer.parseInt(strLine.substring(indexofFourthTab+1, indexofFifthTab));
				intervalName = strLine.substring(indexofFifthTab+1, indexofSixthTab);
				geneHugoSymbol = strLine.substring(indexofSeventhTab+1);
				
//				todo ucscRefSeqGeneList
				if (ucscRefSeqGeneList.contains(geneEntrezId.toString())){
//					Creating millions of nodes with seven attributes causes out of memory error
					IntervalTreeNode node = new IntervalTreeNode(chromName,startPosition,endPosition,refSeqGeneName,geneEntrezId,intervalName,geneHugoSymbol);
					tree.intervalTreeInsert(tree, node);					
				}								
				
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return tree;
	}
		

	
	public IntervalTree createDnaseIntervalTree(String chromName, List<String> dnaseList){
		IntervalTree  dnaseIntervalTree =null;
		FileReader fileReader =null;
		BufferedReader bufferedReader = null;
		
		try {			
			if (Commons.CHROMOSOME1.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR1_DNASE);				
			} else if (Commons.CHROMOSOME2.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR2_DNASE);				
			} else if (Commons.CHROMOSOME3.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR3_DNASE);				
			} else if (Commons.CHROMOSOME4.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR4_DNASE);				
			} else if (Commons.CHROMOSOME5.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR5_DNASE);				
			} else if (Commons.CHROMOSOME6.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR6_DNASE);				
			} else if (Commons.CHROMOSOME7.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR7_DNASE);				
			} else if (Commons.CHROMOSOME8.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR8_DNASE);				
			} else if (Commons.CHROMOSOME9.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR9_DNASE);				
			} else if (Commons.CHROMOSOME10.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR10_DNASE);				
			} else if (Commons.CHROMOSOME11.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR11_DNASE);				
			} else if (Commons.CHROMOSOME12.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR12_DNASE);				
			} else if (Commons.CHROMOSOME13.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR13_DNASE);				
			} else if (Commons.CHROMOSOME14.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR14_DNASE);				
			} else if (Commons.CHROMOSOME15.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR15_DNASE);				
			} else if (Commons.CHROMOSOME16.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR16_DNASE);				
			} else if (Commons.CHROMOSOME17.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR17_DNASE);				
			} else if (Commons.CHROMOSOME18.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR18_DNASE);				
			} else if (Commons.CHROMOSOME19.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR19_DNASE);				
			} else if (Commons.CHROMOSOME20.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR20_DNASE);				
			} else if (Commons.CHROMOSOME21.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR21_DNASE);				
			} else if (Commons.CHROMOSOME22.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR22_DNASE);				
			} else if (Commons.CHROMOSOMEX.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHRX_DNASE);				
			} else if (Commons.CHROMOSOMEY.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHRY_DNASE);				
			} 
		
			bufferedReader = new BufferedReader(fileReader);
			dnaseIntervalTree = generateEncodeDnaseIntervalTree(bufferedReader,dnaseList);
			
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return dnaseIntervalTree;
	}

	public IntervalTree createTfbsIntervalTree(String chromName, List<String> tfbsList){
		IntervalTree  tfbsIntervalTree =null;
		FileReader fileReader =null;
		BufferedReader bufferedReader = null;
		
		try {			
			if (Commons.CHROMOSOME1.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR1_TFBS);				
			} else if (Commons.CHROMOSOME2.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR2_TFBS);				
			} else if (Commons.CHROMOSOME3.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR3_TFBS);				
			} else if (Commons.CHROMOSOME4.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR4_TFBS);				
			} else if (Commons.CHROMOSOME5.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR5_TFBS);				
			} else if (Commons.CHROMOSOME6.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR6_TFBS);				
			} else if (Commons.CHROMOSOME7.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR7_TFBS);				
			} else if (Commons.CHROMOSOME8.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR8_TFBS);				
			} else if (Commons.CHROMOSOME9.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR9_TFBS);				
			} else if (Commons.CHROMOSOME10.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR10_TFBS);				
			} else if (Commons.CHROMOSOME11.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR11_TFBS);				
			} else if (Commons.CHROMOSOME12.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR12_TFBS);				
			} else if (Commons.CHROMOSOME13.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR13_TFBS);				
			} else if (Commons.CHROMOSOME14.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR14_TFBS);				
			} else if (Commons.CHROMOSOME15.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR15_TFBS);				
			} else if (Commons.CHROMOSOME16.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR16_TFBS);				
			} else if (Commons.CHROMOSOME17.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR17_TFBS);				
			} else if (Commons.CHROMOSOME18.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR18_TFBS);				
			} else if (Commons.CHROMOSOME19.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR19_TFBS);				
			} else if (Commons.CHROMOSOME20.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR20_TFBS);				
			} else if (Commons.CHROMOSOME21.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR21_TFBS);				
			} else if (Commons.CHROMOSOME22.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR22_TFBS);				
			} else if (Commons.CHROMOSOMEX.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHRX_TFBS);				
			} else if (Commons.CHROMOSOMEY.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHRY_TFBS);				
			} 
		
			bufferedReader = new BufferedReader(fileReader);
			tfbsIntervalTree = generateEncodeTfbsIntervalTree(bufferedReader,tfbsList);
			
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		
		return tfbsIntervalTree;	
	}

	
	public IntervalTree createHistoneIntervalTree(String chromName,List<String> histoneList){
		IntervalTree  histoneIntervalTree =null;
		FileReader fileReader =null;
		BufferedReader bufferedReader = null;
		
		try {			
			if (Commons.CHROMOSOME1.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR1_HISTONE);				
			} else if (Commons.CHROMOSOME2.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR2_HISTONE);				
			} else if (Commons.CHROMOSOME3.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR3_HISTONE);				
			} else if (Commons.CHROMOSOME4.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR4_HISTONE);				
			} else if (Commons.CHROMOSOME5.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR5_HISTONE);				
			} else if (Commons.CHROMOSOME6.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR6_HISTONE);				
			} else if (Commons.CHROMOSOME7.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR7_HISTONE);				
			} else if (Commons.CHROMOSOME8.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR8_HISTONE);				
			} else if (Commons.CHROMOSOME9.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR9_HISTONE);				
			} else if (Commons.CHROMOSOME10.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR10_HISTONE);				
			} else if (Commons.CHROMOSOME11.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR11_HISTONE);				
			} else if (Commons.CHROMOSOME12.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR12_HISTONE);				
			} else if (Commons.CHROMOSOME13.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR13_HISTONE);				
			} else if (Commons.CHROMOSOME14.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR14_HISTONE);				
			} else if (Commons.CHROMOSOME15.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR15_HISTONE);				
			} else if (Commons.CHROMOSOME16.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR16_HISTONE);				
			} else if (Commons.CHROMOSOME17.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR17_HISTONE);				
			} else if (Commons.CHROMOSOME18.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR18_HISTONE);				
			} else if (Commons.CHROMOSOME19.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR19_HISTONE);				
			} else if (Commons.CHROMOSOME20.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR20_HISTONE);				
			} else if (Commons.CHROMOSOME21.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR21_HISTONE);				
			} else if (Commons.CHROMOSOME22.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHR22_HISTONE);				
			} else if (Commons.CHROMOSOMEX.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHRX_HISTONE);				
			} else if (Commons.CHROMOSOMEY.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_ENCODE_UNSORTED_CHRY_HISTONE);				
			} 
		
			bufferedReader = new BufferedReader(fileReader);
			histoneIntervalTree = generateEncodeHistoneIntervalTree(bufferedReader,histoneList);
			
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		
		return histoneIntervalTree;	
	}
	
	public IntervalTree createUcscRefSeqGenesIntervalTree(String chromName, List<String> ucscRefSeqGeneList){
		IntervalTree  ucscRefSeqGenesIntervalTree =null;
		FileReader fileReader =null;
		BufferedReader bufferedReader = null;
		
		try {			
			if (Commons.CHROMOSOME1.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR1_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME2.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR2_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME3.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR3_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME4.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR4_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME5.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR5_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME6.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR6_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME7.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR7_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME8.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR8_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME9.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR9_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME10.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR10_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME11.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR11_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME12.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR12_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME13.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR13_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME14.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR14_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME15.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR15_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME16.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR16_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME17.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR17_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME18.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR18_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME19.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR19_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME20.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR20_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME21.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR21_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOME22.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHR22_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOMEX.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHRX_REFSEQ_GENES);				
			} else if (Commons.CHROMOSOMEY.equals(chromName)){
					fileReader = new FileReader(Commons.C_ECLIPSE_GANYMEDE_WORKSPACE_DOKTORA_ANNOTATE_UCSCGENOME_UNSORTED_CHRY_REFSEQ_GENES);				
			} 
		
			bufferedReader = new BufferedReader(fileReader);
			ucscRefSeqGenesIntervalTree = generateUcscRefSeqGenesIntervalTree(bufferedReader,ucscRefSeqGeneList);
			
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		
		return ucscRefSeqGenesIntervalTree;	
	
	}
	

	
	public void searchDnase(String chromName,BufferedReader bufferedReader, IntervalTree dnaseIntervalTree, BufferedWriter bufferedWriter){
		String strLine = null;
		int indexofFirstTab = 0 ;
		int indexofSecondTab = 0;
		
		int low;
		int high;
		
		try {
			while((strLine = bufferedReader.readLine())!=null){
				indexofFirstTab = strLine.indexOf('\t');
				indexofSecondTab = strLine.indexOf('\t',indexofFirstTab+1);
				
				low = Integer.parseInt(strLine.substring(indexofFirstTab+1, indexofSecondTab));
				
//				indexofSecondTab must be greater than zero if it exists since indexofFirstTab must exists and can be at least zero therefore indexofSecondTab can be at least one.
				if (indexofSecondTab>0)
					high = Integer.parseInt(strLine.substring(indexofSecondTab+1));
				else 
					high = low;
				
				
				Interval interval = new Interval(low,high);
				bufferedWriter.write("Searched for" + "\t" + chromName + "\t" + low + "\t" + high + "\n");
				bufferedWriter.flush();				
				dnaseIntervalTree.findAllOverlappingDnaseIntervals(dnaseIntervalTree.getRoot(),interval,bufferedWriter);

			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} // End of while 
			
	}
	
	public void searchTfbs(String chromName, BufferedReader bufferedReader, IntervalTree tfbsIntervalTree, BufferedWriter bufferedWriter){
		String strLine = null;
		int indexofFirstTab = 0;
		int indexofSecondTab = 0;
		
		int low;
		int high;
		
		try {
			while((strLine = bufferedReader.readLine())!=null){
				indexofFirstTab = strLine.indexOf('\t');
				indexofSecondTab = strLine.indexOf('\t',indexofFirstTab+1);
				
				low = Integer.parseInt(strLine.substring(indexofFirstTab+1, indexofSecondTab));
				
//				indexofSecondTab must be greater than zero if it exists since indexofFirstTab must exists and can be at least zero therefore indexofSecondTab can be at least one.
				if (indexofSecondTab>0)
					high = Integer.parseInt(strLine.substring(indexofSecondTab+1));
				else 
					high = low;
				
				Interval interval = new Interval(low,high);
				bufferedWriter.write("Searched for" + "\t" + chromName + "\t" + low + "\t" + high + "\n");
				bufferedWriter.flush();								
				tfbsIntervalTree.findAllOverlappingTfbsIntervals(tfbsIntervalTree.getRoot(),interval,bufferedWriter);

			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} // End of while 
	}
	
	public void searchHistone(String chromName, BufferedReader bufferedReader, IntervalTree histoneIntervalTree, BufferedWriter bufferedWriter){
		String strLine = null;
		int indexofFirstTab = 0;
		int indexofSecondTab = 0;
		
		int low;
		int high;
		
		try {
			while((strLine = bufferedReader.readLine())!=null){
				indexofFirstTab = strLine.indexOf('\t');
				indexofSecondTab = strLine.indexOf('\t',indexofFirstTab+1);
				
				low = Integer.parseInt(strLine.substring(indexofFirstTab+1, indexofSecondTab));
				
//				indexofSecondTab must be greater than zero if it exists since indexofFirstTab must exists and can be at least zero therefore indexofSecondTab can be at least one.
				if (indexofSecondTab>0)
					high = Integer.parseInt(strLine.substring(indexofSecondTab+1));
				else 
					high = low;
				
				Interval interval = new Interval(low,high);
				bufferedWriter.write("Searched for" + "\t" + chromName + "\t" + low + "\t" + high + "\n");
				bufferedWriter.flush();				
				histoneIntervalTree.findAllOverlappingHistoneIntervals(histoneIntervalTree.getRoot(),interval,bufferedWriter);

			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} // End of while 
	}
	
	public void searchUcscRefSeqGenes(String chromName, BufferedReader bufferedReader, IntervalTree ucscRefSeqGenesIntervalTree, BufferedWriter bufferedWriter){
		String strLine = null;
		int indexofFirstTab = 0;
		int indexofSecondTab = 0;
		
		int low;
		int high;
		
		try {
			while((strLine = bufferedReader.readLine())!=null){
				indexofFirstTab = strLine.indexOf('\t');
				indexofSecondTab = strLine.indexOf('\t',indexofFirstTab+1);
				
				low = Integer.parseInt(strLine.substring(indexofFirstTab+1, indexofSecondTab));
				
//				indexofSecondTab must be greater than zero if it exists since indexofFirstTab must exists and can be at least zero therefore indexofSecondTab can be at least one.
				if (indexofSecondTab>0)
					high = Integer.parseInt(strLine.substring(indexofSecondTab+1));
				else 
					high = low;
				
				Interval interval = new Interval(low,high);
				bufferedWriter.write("Searched for" + "\t" + chromName + "\t" + low + "\t" + high + "\n");
				bufferedWriter.flush();				
				ucscRefSeqGenesIntervalTree.findAllOverlappingUcscRefSeqGenesIntervals(ucscRefSeqGenesIntervalTree.getRoot(),interval,bufferedWriter);
				
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} // End of while 
	}
	

	public BufferedReader createBufferedReader(String fileName){
		FileReader fileReader = null;
		BufferedReader bufferedReader = null;
		
		try {
			fileReader = new FileReader(fileName);
			bufferedReader = new BufferedReader(fileReader);
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
		return bufferedReader;
	}
	
	

	
	
	public void searchEachChromBaseInputFile(String outputFileName,List<String> dnaseList, List<String> tfbsList, List<String> histoneList, List<String> ucscRefSeqGeneList, List<String> keggPathway2NcbiGeneIdList){
		
		BufferedReader bufferedReader =null ;
		
		IntervalTree dnaseIntervalTree;
		IntervalTree histoneIntervalTree;
		IntervalTree tfbsIntervalTree;
		IntervalTree ucscRefSeqGenesIntervalTree;	
		IntervalTree keggPathway2NcbiGeneIdsIntervalTree;
		
		FileWriter fileWriter;
		BufferedWriter bufferedWriter = null;
		
		try {
			fileWriter = new FileWriter(outputFileName);
			bufferedWriter = new BufferedWriter(fileWriter);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		for(int i = 1; i<=24 ; i++ ){
			
			switch(i){
			case 1: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME1,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR1_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME1,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME1,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR1_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME1,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME1,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR1_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME1,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME1,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR1_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME1,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;								
					
					keggPathway2NcbiGeneIdsIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME1,keggPathway2NcbiGeneIdList);
					bufferedReader = createBufferedReader(Commons.SEARCH_CHR1_USING_INTERVAL_TREE_INPUT_FILE);
					searchUcscRefSeqGenes(Commons.CHROMOSOME1,bufferedReader, keggPathway2NcbiGeneIdsIntervalTree, bufferedWriter);
					keggPathway2NcbiGeneIdsIntervalTree = null;					
					break;
					
//			case 2: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME2,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR2_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME2,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME2,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR2_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME2,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//	
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME2,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR2_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME2,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME2,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR2_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME2,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//					
//			case 3: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME3,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR3_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME3,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME3,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR3_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME3,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//	
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME3,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR3_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME3,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME3,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR3_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME3,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//					
//			case 4: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME4,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR4_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME4,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME4,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR4_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME4,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//	
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME4,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR4_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME4,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME4,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR4_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME4,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//				
//			case 5: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME5,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR5_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME5,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME5,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR5_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME5,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//	
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME5,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR5_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME5,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME5,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR5_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME5,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//		
//		case 6: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME6,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR6_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME6,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME6,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR6_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME6,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//	
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME6,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR6_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME6,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME6,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR6_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME6,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//					
//		case 7: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME7,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR7_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME7,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME7,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR7_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME7,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME7,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR7_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME7,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME7,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR7_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME7,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//
//
//		case 8: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME8,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR8_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME8,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME8,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR8_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME8,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME8,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR8_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME8,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME8,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR8_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME8,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//
//		case 9: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME9,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR9_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME9,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME9,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR9_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME9,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME9,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR9_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME9,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME9,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR9_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME9,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//					
//		case 10: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME10,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR10_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME10,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME10,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR10_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME10,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME10,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR10_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME10,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME10,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR10_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME10,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//					
//		case 11: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME11,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR11_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME11,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME11,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR11_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME11,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME11,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR11_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME11,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME11,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR11_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME11,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//
//		case 12: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME12,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR12_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME12,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME12,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR12_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME12,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME12,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR12_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME12,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME12,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR12_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME12,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//		case 13: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME13,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR13_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME13,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME13,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR13_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME13,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME13,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR13_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME13,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME13,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR13_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME13,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;		
//				
//		case 14: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME14,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR14_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME14,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME14,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR14_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME14,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME14,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR14_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME14,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME14,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR14_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME14,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;		
//					
//		case 15: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME15,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR15_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME15,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME15,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR15_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME15,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME15,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR15_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME15,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME15,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR15_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME15,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;		
//						
//		case 16: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME16,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR16_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME16,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME16,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR16_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME16,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME16,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR16_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME16,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME16,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR16_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME16,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;		
//							
//		case 17: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME17,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR17_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME17,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME17,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR17_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME17,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME17,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR17_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME17,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME17,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR17_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME17,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;		
//								
//		case 18: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME18,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR18_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME18,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME18,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR18_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME18,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME18,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR18_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME18,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME18,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR18_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME18,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;		
//									
//		case 19: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME19,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR19_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME19,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME19,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR19_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME19,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME19,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR19_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME19,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME19,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR19_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME19,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;		
//										
//		case 20: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME20,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR20_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME20,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME20,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR20_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME20,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME20,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR20_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME20,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME20,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR20_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME20,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;		
//											
//		case 21: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME21,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR21_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME21,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME21,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR21_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME21,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME21,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR21_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME21,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME21,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR21_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME21,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;		
//												
//		case 22: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOME22,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR22_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOME22,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOME22,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR22_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOME22,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOME22,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR22_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOME22,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOME22,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHR22_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOME22,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;		
//													
//		case 23: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOMEX,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHRX_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOMEX,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOMEX,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHRX_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOMEX,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOMEX,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHRX_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOMEX,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOMEX,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHRX_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOMEX,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;
//					
//		case 24: 			
//					dnaseIntervalTree = createDnaseIntervalTree(Commons.CHROMOSOMEY,dnaseList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHRY_USING_INTERVAL_TREE_INPUT_FILE);
//					searchDnase(Commons.CHROMOSOMEY,bufferedReader, dnaseIntervalTree, bufferedWriter);
//					dnaseIntervalTree = null;					
//					
//					tfbsIntervalTree = createTfbsIntervalTree(Commons.CHROMOSOMEY,tfbsList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHRY_USING_INTERVAL_TREE_INPUT_FILE);
//					searchTfbs(Commons.CHROMOSOMEY,bufferedReader, tfbsIntervalTree, bufferedWriter);
//					tfbsIntervalTree = null;
//		
//					histoneIntervalTree = createHistoneIntervalTree(Commons.CHROMOSOMEY,histoneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHRY_USING_INTERVAL_TREE_INPUT_FILE);
//					searchHistone(Commons.CHROMOSOMEY,bufferedReader, histoneIntervalTree, bufferedWriter);
//					histoneIntervalTree = null;
//					
//					ucscRefSeqGenesIntervalTree = createUcscRefSeqGenesIntervalTree(Commons.CHROMOSOMEY,ucscRefSeqGeneList);
//					bufferedReader = createBufferedReader(Commons.SEARCH_CHRY_USING_INTERVAL_TREE_INPUT_FILE);
//					searchUcscRefSeqGenes(Commons.CHROMOSOMEY,bufferedReader, ucscRefSeqGenesIntervalTree, bufferedWriter);
//					ucscRefSeqGenesIntervalTree = null;					
//					break;					

			}// End of Switch 						
		}// End of For
		
		try {
			bufferedReader.close();
			bufferedWriter.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
	}

	public void fillDnaseNameList(List<String> dnaseNameList, String dnaseInputFileName){
		String strLine;
		FileReader fileReader = null;
		BufferedReader bufferedReader = null;
		
		try {
			fileReader = new FileReader(dnaseInputFileName);			
			bufferedReader = new BufferedReader(fileReader);
			
			while((strLine = bufferedReader.readLine())!=null) {
				dnaseNameList.add(strLine);				
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try {
			bufferedReader.close();
			fileReader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	
		
	}

	public void fillTfbsNameList(List<String> tfbsNameList,String tfbsInputFileName){
		String strLine;
		FileReader fileReader = null;
		BufferedReader bufferedReader = null;
		
		try {
			fileReader = new FileReader(tfbsInputFileName);			
			bufferedReader = new BufferedReader(fileReader);
			
			while((strLine = bufferedReader.readLine())!=null) {
				tfbsNameList.add(strLine);				
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}		
		
		try {
			bufferedReader.close();
			fileReader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	
	}

	public void fillHistoneNameList(List<String> histoneNameList,String histoneInputFileName){
		String strLine;
		FileReader fileReader = null;
		BufferedReader bufferedReader = null;
		
		try {
			fileReader = new FileReader(histoneInputFileName);			
			bufferedReader = new BufferedReader(fileReader);
			
			while((strLine = bufferedReader.readLine())!=null) {
				histoneNameList.add(strLine);				
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try {
			bufferedReader.close();
			fileReader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	
	}

	public void fillNcbiGeneIdList(List<String> ncbiGeneIdList, String ncbiGeneIdInputFileName){
		String strLine;
		FileReader fileReader = null;
		BufferedReader bufferedReader = null;
		
		try {
			fileReader = new FileReader(ncbiGeneIdInputFileName);			
			bufferedReader = new BufferedReader(fileReader);
			
			while((strLine = bufferedReader.readLine())!=null) {
				ncbiGeneIdList.add(strLine);				
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}		
		
		try {
			bufferedReader.close();
			fileReader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	
	}

	public void fillKeggPathwayNameList(List<String> keggPathwayNameList,String keggPathwayInputFileName){
		String strLine;
		FileReader fileReader = null;
		BufferedReader bufferedReader = null;
		
		try {
			fileReader = new FileReader(keggPathwayInputFileName);			
			bufferedReader = new BufferedReader(fileReader);
			
			while((strLine = bufferedReader.readLine())!=null) {
				keggPathwayNameList.add(strLine);				
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}		
		
		try {
			bufferedReader.close();
			fileReader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	
	}

	public void fillKeggPathway2NcbiGeneIdList(List<String> keggPathwayNameList, String keggPathway2NcbiGeneIdsInputFileName, List<String> keggPathway2NcbiGeneIdsList){
		String strLine;
		FileReader fileReader = null;
		BufferedReader bufferedReader = null;
		
		int indexofFirstTab 	= -1;
		int indexofSecondTab 	= -1;
		int indexofFirstColon 		= -1;
		int indexofSecondColon 		= -1;
		
		String keggPathwayName;
		String ncbiGeneId;
		
		try {
			fileReader = new FileReader(keggPathway2NcbiGeneIdsInputFileName);
			bufferedReader = new BufferedReader(fileReader);
			
			while((strLine = bufferedReader.readLine())!=null){

				indexofFirstTab 	= strLine.indexOf('\t');
				indexofSecondTab 	= strLine.indexOf('\t',indexofFirstTab+1);
				
				keggPathwayName 	= strLine.substring(0,indexofFirstTab);
				indexofFirstColon 	= keggPathwayName.indexOf(':');
				keggPathwayName 	= keggPathwayName.substring(indexofFirstColon+1);				
				
				
				if(keggPathwayNameList.contains(keggPathwayName)){
					
					ncbiGeneId = strLine.substring(indexofFirstTab+1,indexofSecondTab);
					indexofSecondColon = ncbiGeneId.indexOf(':');					
					ncbiGeneId = ncbiGeneId.substring(indexofSecondColon+1);
					 
//					Add only unique ncbi gene id 
					if(!(keggPathway2NcbiGeneIdsList.contains(ncbiGeneId))){
						keggPathway2NcbiGeneIdsList.add(ncbiGeneId);
					}				
				}																
			} // End of While
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try {
			bufferedReader.close();
			fileReader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}	
	}
	
	public static void main(String[] args) {
		AnnotateIntervalsForGivenParameters annotateIntervals = new AnnotateIntervalsForGivenParameters();
		List<BufferedWriter> bufferedWriterList = new ArrayList<BufferedWriter>();
		
		List<String> dnaseNameList = new ArrayList<String>();
		List<String> tfbsNameList = new ArrayList<String>();
		List<String> histoneNameList = new ArrayList<String>();
		List<String> ncbiGeneIdList = new ArrayList<String>();
		List<String> keggPathwayNameList = new ArrayList<String>();
		List<String> keggPathway2NcbiGeneIdsList = new ArrayList<String>();
		
		
		annotateIntervals.fillDnaseNameList(dnaseNameList,Commons.ANNOTATE_INTERVALS_WITH_DNASE_USING_INTERVAL_TREE_INPUT_FILE);
		annotateIntervals.fillTfbsNameList(tfbsNameList,Commons.ANNOTATE_INTERVALS_WITH_TFBS_USING_INTERVAL_TREE_INPUT_FILE);
		annotateIntervals.fillHistoneNameList(histoneNameList,Commons.ANNOTATE_INTERVALS_WITH_HISTONE_USING_INTERVAL_TREE_INPUT_FILE);
		annotateIntervals.fillNcbiGeneIdList(ncbiGeneIdList,Commons.ANNOTATE_INTERVALS_WITH_NCBI_GENES_USING_INTERVAL_TREE_INPUT_FILE);
		annotateIntervals.fillKeggPathwayNameList(keggPathwayNameList,Commons.ANNOTATE_INTERVALS_WITH_KEGG_PATHWAY_USING_INTERVAL_TREE_INPUT_FILE);
		
		annotateIntervals.fillKeggPathway2NcbiGeneIdList(keggPathwayNameList,Commons.KEGG_PATHWAY_2_NCBI_GENE_IDS_INPUT_FILE,keggPathway2NcbiGeneIdsList);
		
		annotateIntervals.createChromBaseSeachInputFiles(bufferedWriterList);		
		annotateIntervals.partitionSearchInputFilePerChromName(Commons.ANNOTATE_INTERVALS_USING_INTERVAL_TREE_INPUT_FILE,bufferedWriterList);
		annotateIntervals.closeBufferedWriterList(bufferedWriterList);		
		annotateIntervals.searchEachChromBaseInputFile(Commons.ANNOTATE_INTERVALS_USING_INTERVAL_TREE_OUTPUT_FILE,dnaseNameList,tfbsNameList,histoneNameList,ncbiGeneIdList,keggPathway2NcbiGeneIdsList);
		
	}

}
